//
//  LBMeThreeBtn.m
//  loveBeen
//
//  Created by lc on 2016/11/21.
//  Copyright © 2016年 loveBeen. All rights reserved.
//

#import "LBMeThreeBtn.h"
#import "NSAttributedString+LBMeAdditon.h"

@interface LBMeThreeBtn()
@property(nonatomic,strong)NSMutableArray *arrM;
@end

@implementation LBMeThreeBtn


-(instancetype)init {
    self = [super init];
    if (self) {
        self.arrM = [NSMutableArray array];
        [self setupUI];
    }
    
    return self;
}

-(void)setupUI {
    
    
    //添加三个图文混排button
    
    [self addTopButton:@"v2_my_order_icon" title:@"我的订单" tag: kButtonOrder];
    [self addTopButton:@"v2_my_coupon_icon" title:@"优惠券" tag:kButtonCheap];
    [self addTopButton:@"v2_my_message_icon" title:@"我的消息" tag:kButtonMessage];

    //布局
    [self.arrM mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:1 leadSpacing:0 tailSpacing:0];
    [self.arrM mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
    }];
}

- (void)addTopButton:(NSString *)imageName title:(NSString *)title tag:(HomeTopButtonType)tag{
    //设置一个图文混排的button
    UIButton *button = [[UIButton alloc]init];
    button.backgroundColor = [UIColor whiteColor];
    //使用分类给按钮设置一个图文混排的按钮
    [button setAttributedTitle:[NSAttributedString Me_imageTextWithImage:[UIImage imageNamed:imageName] imageWH:28 title:title fontSize:16 titleColor:[UIColor grayColor] spacing:7] forState:UIControlStateNormal];
    //设置按钮的行数为0,让按钮上的文字自动换行
    button.titleLabel.numberOfLines = 0;
    //设置按钮文字的对齐方式为居中对齐
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    //让按钮自适应大小
    [button sizeToFit];
    
    
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];

    button.tag = tag;
    
    
    [self addSubview:button];
    
   
    [self.arrM addObject:button];
}

-(void)clickButton:(UIButton *)btn {
    if ([_delegate respondsToSelector:@selector(LBMeThreeBt:)]) {
        [_delegate LBMeThreeBt:btn];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
